package com.cxyd.modules.wms.controller;

import com.cxyd.common.Utils.ExcelUtils;
import com.cxyd.common.page.PageData;
import com.cxyd.common.utils.Result;
import com.cxyd.modules.wms.dto.StockExpiryDTO;
import com.cxyd.modules.wms.dto.StockOverdueDTO;
import com.cxyd.modules.wms.excel.StockExpiryExcel;
import com.cxyd.modules.wms.excel.StockOverdueExcel;
import com.cxyd.modules.wms.service.StockExpiryService;
import com.cxyd.modules.wms.service.StockOverdueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 库存信息
 *
 * @author g_Cycle gengruyi01@163.com
 * @since 1.0.0 2023-04-27
 */
@RestController
@RequestMapping("wms/stockoverdue")
public class StockOverdueController {
    @Resource
    private StockOverdueService stockOverdueService;
    @Resource
    private StockExpiryService stockExpiryService;

    @GetMapping("page")
    @RequiresPermissions("wms:stock:page")
    public Result<PageData<StockOverdueDTO>> page(@RequestParam Map<String, Object> params) {
        PageData<StockOverdueDTO> page = stockOverdueService.page(params);

        return new Result<PageData<StockOverdueDTO>>().ok(page);
    }

    @GetMapping("expiryPage")
    @RequiresPermissions("wms:stock:expiryPage")
    public Result<PageData<StockExpiryDTO>> expiryPage(@RequestParam Map<String, Object> params) {
        PageData<StockExpiryDTO> page = stockExpiryService.page(params);

        return new Result<PageData<StockExpiryDTO>>().ok(page);
    }

    @GetMapping("export")
    public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
        List<StockOverdueDTO> list = stockOverdueService.getList(params);
        ExcelUtils.exportExcelToTarget(response, null, list, StockOverdueExcel.class);
    }

    @GetMapping("expiry-export")
    public void expiryExport(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
        List<StockExpiryDTO> list = stockExpiryService.getList(params);
        ExcelUtils.exportExcelToTarget(response, null, list, StockExpiryExcel.class);
    }
}